package com.gc.business.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gc.business.domain.AnnualInspection;
import com.gc.business.mapper.AnnualInspectionMapper;
import com.gc.business.service.IAnnualInspectionService;
import com.gc.business.service.IAnnualPlanService;
import com.gc.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 电梯年检管理 服务层实现
 * 
 * @author hruiyan
 * @date 2020-12-01
 */
@Slf4j
@Service
public class AnnualInspectionServiceImpl extends ServiceImpl<AnnualInspectionMapper, AnnualInspection> implements IAnnualInspectionService {

    @Autowired
    private IAnnualPlanService annualPlanService;

    @Override
    public List<AnnualInspection> list(AnnualInspection annualInspection,List<Long> collect){

        LambdaQueryWrapper<AnnualInspection> wrapper = new LambdaQueryWrapper<>();
        if(annualInspection != null){
            if(StringUtils.isNotEmpty(annualInspection.getInspectionId())){
                wrapper.eq(AnnualInspection::getInspectionId, annualInspection.getInspectionId());
            }
            if(StringUtils.isNotEmpty(annualInspection.getElevatorName())){
                wrapper.like(AnnualInspection::getElevatorName, annualInspection.getElevatorName());
            }
            if(StringUtils.isNotEmpty(annualInspection.getAnnualDate())){
                wrapper.eq(AnnualInspection::getAnnualDate, annualInspection.getAnnualDate());
            }
            if(StringUtils.isNotEmpty(annualInspection.getCheckSpeedLimiter())){
                wrapper.eq(AnnualInspection::getCheckSpeedLimiter, annualInspection.getCheckSpeedLimiter());
            }
            if(StringUtils.isNotEmpty(annualInspection.getCheckThrough())){
                wrapper.eq(AnnualInspection::getCheckThrough, annualInspection.getCheckThrough());
            }
            if(StringUtils.isNotEmpty(annualInspection.getInspectionStatus())){
                wrapper.eq(AnnualInspection::getInspectionStatus, annualInspection.getInspectionStatus());
            }
            if(StringUtils.isNotEmpty(annualInspection.getHeadMan())){
                wrapper.like(AnnualInspection::getHeadMan, annualInspection.getHeadMan());
            }
            if(StringUtils.isNotEmpty(annualInspection.getHeadUserId())){
                wrapper.eq(AnnualInspection::getHeadUserId, annualInspection.getHeadUserId());
            }
            if(StringUtils.isNotEmpty(annualInspection.getStartTime())){
                wrapper.eq(AnnualInspection::getStartTime, annualInspection.getStartTime());
            }
            if(StringUtils.isNotEmpty(annualInspection.getCompletionTime())){
                wrapper.eq(AnnualInspection::getCompletionTime, annualInspection.getCompletionTime());
            }
            if(StringUtils.isNotEmpty(annualInspection.getInspectionContext())){
                wrapper.like(AnnualInspection::getInspectionContext, annualInspection.getInspectionContext());
            }
            if(StringUtils.isNotEmpty(annualInspection.getInspectionImg())){
                wrapper.eq(AnnualInspection::getInspectionImg, annualInspection.getInspectionImg());
            }
            if(StringUtils.isNotEmpty(annualInspection.getCreateBy())){
                wrapper.eq(AnnualInspection::getCreateBy, annualInspection.getCreateBy());
            }
            if(StringUtils.isNotEmpty(annualInspection.getCreateTime())){
                wrapper.eq(AnnualInspection::getCreateTime, annualInspection.getCreateTime());
            }
            if(StringUtils.isNotEmpty(annualInspection.getUpdateBy())){
                wrapper.eq(AnnualInspection::getUpdateBy, annualInspection.getUpdateBy());
            }
            if(StringUtils.isNotEmpty(annualInspection.getUpdateTime())){
                wrapper.eq(AnnualInspection::getUpdateTime, annualInspection.getUpdateTime());
            }
            if(StringUtils.isNotEmpty(annualInspection.getRemark())){
                wrapper.eq(AnnualInspection::getRemark, annualInspection.getRemark());
            }
            if(StringUtils.isNotEmpty(annualInspection.getPlanId())){
                wrapper.eq(AnnualInspection::getPlanId, annualInspection.getPlanId());
            }
            //年检计划挂钩
            if (CollUtil.isNotEmpty(collect)){
                wrapper.in(AnnualInspection::getPlanId,collect);
            }
        }
        return baseMapper.selectList(wrapper);
    }


    /**
     * 查询任务不同状态下的年检列表
     * @param attrId 所属公司ID
     * @param reviewType 0.待启动 1.待确定 2.确定完成
     * @param headUserId 接取任务的负责人ID
     * @return
     */
    @Override
    public List<Map<String,Object>> selectAnnualInspectionList(Long attrId, String reviewType, Long headUserId){
        return baseMapper.selectAnnualInspectionList(attrId,reviewType,headUserId);
    }


}
